var UserModel = require('../model/user');

var that = {};

var addUser = function(data, callback) {
  console.log('insert data', data);

  var data = {
    trades: 'trades',
    stock_positions: 'stock_positions',
    summary: 'summary',
    benchmark_portfolio: 'benchmark_portfolio',
    portfolio: 'stock_positions',
    stock_positions: 'portfolio',
    stock_account: 'stock_account',
  };

  UserModel.create(data, function(err) {
    var result;

    if (err) {
      result = {
        retMsg: err,
        retCode: 500
      };
    } else {
      result = {
        retMsg: '插入成功',
        retCode: 200
      };
    };

    console.log(result);

    callback(result);
  });
};

var findUser = function(data, callback) {
  UserModel.find({}, function (err, doc){
    var result;

    if (err) {
      result = {
        retMsg: err,
        retCode: 500
      };
    } else {
      result = {
        data: doc,
        retMsg: '查询成功',
        retCode: 200
      };
    };

    console.log(result);
    callback(result);
  });
};

that.addUser = addUser;
that.findUser = findUser;

module.exports = that;
